﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using League.Entity;
using League.Business;
using League.DataAccess;

public partial class Page_Ranking : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LeagueBind();
        }
    }

    private void Ranking()
    {
        int begin = 0; int end = 0;
        int.TryParse(txtBegin.Text, out begin);
        int.TryParse(txtEnd.Text, out end);

        while (begin < end)
        {
            List<LeagueTeamRanking> leagueTeamRankingSet =
                LeagueTeamRankingController.CountRankingByRoundNumber(ddlLeague.SelectedValue, begin);

            foreach (LeagueTeamRanking leagueMatch in leagueTeamRankingSet)
            {
                LeagueTeamRankingController.InsertOrUpdate(leagueMatch);
            }
            begin++;
        }
    }

    private void LeagueBind()
    {
        List<LeagueInfo> leagueInfoSet = LeagueInfoDataAccess.GetAllLeagueInfo();
        foreach (LeagueInfo leagueInfo in leagueInfoSet)
        {
            ddlLeague.Items.Add(new ListItem(leagueInfo.SeasonYear.ToString() + " - " +
                leagueInfo.LeagueName, leagueInfo.LeagueID.ToString()));
        }
    }
    protected void btnRanking_Click(object sender, EventArgs e)
    {
        Ranking();
    }
}